package com.soonfor.evaluate.presenter;
import android.content.Context;
import com.google.gson.Gson;
import com.soonfor.evaluate.bean.RequestTemplateDto;
import com.soonfor.evaluate.http.api.Request;
import com.soonfor.evaluate.http.httptools.AsyncUtils;
import com.soonfor.evaluate.activity.EvaluateCustomersActivity;
import com.soonfor.evaluate.base.IEvalBasePresenter;
import com.soonfor.evaluate.bean.EvalCustSaveBean;
import com.soonfor.evaluate.bean.EvaluateTemplateBean;
/**
 * 作者：DC-DingYG on 2018-10-19 14:29
 * 邮箱：dingyg012655@126.com
 */
public class EvaluateCustomersPresenter implements IEvalBasePresenter, AsyncUtils.AsyncCallback {

    EvaluateCustomersActivity mActivity;

    public EvaluateCustomersPresenter(EvaluateCustomersActivity mActivity) {
        this.mActivity = mActivity;
    }

    /**
     * 获取评价模板
     */
    public void getEvaluateTemplateBean(Context cxt, RequestTemplateDto templateDto) {
        Request.Evaluate.getAppraiseprj(cxt,templateDto.getGetdatatype(), templateDto.getFappraiseoritype(), templateDto.getFappraiseoriid(),
                Request.Evaluate.POST_GETEVALUATETEMP, this);
    }

    /**
     * 评价客户（保存）
     */
    public void saveEvalCustomer(Context cxt, EvalCustSaveBean saveBean) {
        Request.Evaluate.saveEvaluateCustomer(cxt, saveBean, this);
    }

    @Override
    public void success(int requestCode, String data) {
        switch (requestCode) {
            case Request.Evaluate.POST_GETEVALUATETEMP:
                try {
                    EvaluateTemplateBean templateBean = new Gson().fromJson(data, EvaluateTemplateBean.class);
                    if (templateBean != null) {
                        mActivity.showViewByData(true, templateBean);
                    } else {
                        mActivity.showViewByData(false, templateBean);
                    }
                }catch (Exception e){}
                break;
            case Request.Evaluate.POST_SAVEEVALCUSTOMER:
                mActivity.refreshAfterSave(true, data);
                break;
        }
    }

    @Override
    public void fail(int requestCode, int statusCode, String data, String msg) {
        switch (requestCode) {
            case Request.Evaluate.POST_GETEVALUATETEMP:
                mActivity.showViewByData(false, null);
                break;
            case Request.Evaluate.POST_SAVEEVALCUSTOMER:
                mActivity.refreshAfterSave(false, "保存失败");
                break;
        }
    }

}
